package com.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.service.HotEventsService;


@CrossOrigin
@RestController
public class HotEventsController {
    @Autowired
    private HotEventsService hotEventsService;

    @Cacheable(value = "getHotEvents")
    @GetMapping("/getHotEvents")
    public Object getHotEvents(@RequestParam Integer currentNo, @RequestParam String keyWord) {
        return JSON.toJSONStringWithDateFormat(hotEventsService.getHotEvents(currentNo, keyWord), "yyyy-MM-dd");
    }

    @GetMapping("/getHotEventInfo")
    public Object getHotEventInfo(@RequestParam Integer id) {
        return JSON.toJSONStringWithDateFormat(hotEventsService.getHotEventInfo(id), "yyyy-MM-dd");
    }

    @Scheduled(cron = "0 0 15 * * ?")
    public void updateSearchSum() {
        hotEventsService.updateSearchSum();
    }

}
